var _inherit = require('core/inherit.js');
var _UIContainer = require('component/uicontainer.js');
var _global = require('game/global.js');
var _button = require('widget/button.js');
var R = require('game/texture.js').R;

function createButton(order, position) {
    var up = _global.spriteNode(R.map.common.bt_apple_u);
    var down = _global.spriteNode(R.map.common.bt_apple_d);
    var bt = _button.createButtonWithId(order, up, down);
    bt.setAnchor(0.5, 0.5);
    bt.setPosition(position);
    return bt;
};

function Map(mapconfig) {
    _UIContainer.call(this);

    this.mBg = _global.spriteNode(mapconfig.bg);
    this.addChild(this.mBg);
    this.setSize(this.mBg.getSize());

    var buttons = mapconfig.buttons;
    for (var i = 0, l = buttons.length; i < l; i++) {
        this.addChild(createButton(i, buttons[i]));
    }
}
_inherit(Map, _UIContainer);
Map.prototype.mTag = 'map';

module.exports = Map;